#!/usr/bin/env python3.8
# -*- encoding: utf-8 -*-
'''
@File    :   settings.py
@Time    :   2021/10/13 16:49:25
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib
import os
from dotenv import load_dotenv

basedir = os.path.abspath(os.path.dirname(__file__))
load_dotenv(os.path.join(basedir, '.flaskenv'))


class Operations:
    CONFIRM = 'confirm'
    RESET_PASSWORD = 'reset-password'
    CHANGE_EMAIL = 'change-email'

class BaseConfig(object):
    """项目配置核心类"""
    #调试模式
    DEBUG=True
    #注意：不要填写zh_CN。有坑
    LANGUAGES = ['en', 'zh']
    # 配置日志
    # LOG_LEVEL = "DEBUG"
    LOG_LEVEL = "INFO"
    # #数据库连接格式
    # SQLALCHEMY_DATABASE_URI = "mysql+pymysql://user:password@localhost:3306/test?charset=utf8"
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'you will never guess'
    #设置文件上传的大小
    MAX_CONTENT_LENGTH = 3 * 1024 * 1024
    # 动态追踪修改设置，如未设置只会提示警告
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 查询时会显示原始SQL语句
    SQLALCHEMY_ECHO = False
    # 数据库连接池的大小
    SQLALCHEMY_POOL_SIZE=10
    #指定数据库连接池的超时时间
    SQLALCHEMY_POOL_TIMEOUT=10
    #确定每页显示多少个项目数
    POSTS_PER_PAGE = 20
    #每页显示图片数目
    ALBUMY_PHOTO_PER_PAGE = 12
    
    ADMIN_EMAIL = 'liefengwind@163.com'
    #增加邮箱基本信息
    MAIL_SERVER = os.environ.get('MAIL_SERVER')
    MAIL_PORT = int(os.environ.get('MAIL_PORT') or 25)
    MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS')
    MAIL_USE_SSL = os.environ.get('MAIL_USE_SSL', 'false').lower() in ['true', 'on', '1']
    MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
    #客户端授权密码
    MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
    MAIL_DEFAULT_SENDER = ('Albumy Admin', MAIL_USERNAME)
    #app基本配置设置
    ALBUMY_ADMIN_EMAIL = os.getenv('ALBUMY_ADMIN', 'liefengwind@163.com')
    ALBUMY_MAIL_SUBJECT_PREFIX = '[Albumy]'
    #上传图片保存位置，图片大小和命名
    ALBUMY_UPLOAD_PATH = os.path.join(basedir,'uploads')
    ALBUMY_PHOTO_SIZE = {'small': 400,
                         'medium': 800}
    ALBUMY_PHOTO_SUFFIX = {
                            ALBUMY_PHOTO_SIZE['small']: '_s',  # thumbnail
                            ALBUMY_PHOTO_SIZE['medium']: '_m',  # display
                            }
    
    DROPZONE_ALLOWED_FILE_CUSTOM = True
    #允许上传的文件类型
    AVATARS_SAVE_PATH = os.path.join(ALBUMY_UPLOAD_PATH, 'avatars')
    AVATARS_SIZE_TUPLE = (30, 100, 200)
    
    DROPZONE_ALLOWED_FILE_TYPE = 'image/*,.pdf,.txt'
    DROPZONE_MAX_FILE_SIZE = 3
    DROPZONE_MAX_FILES = 30
    #设置CSRF开启
    DROPZONE_ENABLE_CSRF = True


class DevelopmentConfig(BaseConfig):
    #数据库连接格式
    HOST = '127.0.0.1'
    PORT = '3306'
    DATABASE = 'albumy_test'
    USENAME = 'root'
    PASSWORD = '123456'
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://{usename}:{password}@{host}:{port}/{database}?charset=utf8".format( usename = USENAME,
                                                                                                                    password = PASSWORD,
                                                                                                                    host = HOST,
                                                                                                                    port = PORT,
                                                                                                                    database = DATABASE,)
    AVATARS_SAVE_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static/avatars/')

class TestingConfig(BaseConfig):
    TESTING = True
    WTF_CSRF_ENABLED = False
    SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'  # in-memory database



class ProductionConfig(BaseConfig):
   #数据库连接格式
    HOST = '127.0.0.1'
    PORT = '3306'
    DATABASE = 'albumy'
    USENAME = 'root'
    PASSWORD = '123456'
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://{usename}:{password}@{host}:{port}/{database}?charset=utf8".format( usename = USENAME,
                                                                                                                    password = PASSWORD,
                                                                                                                    host = HOST,
                                                                                                                    port = PORT,
                                                                                                                    database = DATABASE,)
    AVATARS_SAVE_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'static/avatars/')


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig
}